﻿using Entities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmConfig : Form
    {
        
        public frmConfig()
        {
            InitializeComponent();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                ServerConfig sc = new ServerConfig(txtIpServer.Text.ToString(), txtTenCSDL.Text.ToString(), txtTenDangNhap.Text.ToString(), txtMatKhau.Text.ToString());
                ServerConfigManager.serializeServerConfig(sc, Constant.CONST_FILE_NAME_SERVER_CONFIG);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            MessageBox.Show("Lưu Thành Công !");
            
        }

        private void frmConfig_Load(object sender, EventArgs e)
        {
            try
            {
                ServerConfig sc = ServerConfigManager.deserializeServerConfig(Constant.CONST_FILE_NAME_SERVER_CONFIG);
                txtIpServer.Text = sc.ipServer;
                txtTenCSDL.Text = sc.dbName;
                txtTenDangNhap.Text = sc.user;
                txtMatKhau.Text = sc.pwd;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }                      
        }
    }
}
